package com.leon.androidui

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.leon.androidui.customview.CustomMainActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        rv.layoutManager = LinearLayoutManager(this)
        val datas = arrayListOf<ItemModel>(ItemModel("自定义View", CustomMainActivity::class.java))
        val mAdapter = MainAdapter(datas)
        mAdapter.setOnItemClickListener { baseQuickAdapter: BaseQuickAdapter<*, *>, view: View, position: Int ->
            startActivity(Intent(this@MainActivity, datas[position].clazz))
        }
        rv.adapter = mAdapter
    }

    class MainAdapter(datas: MutableList<ItemModel>) :
        BaseQuickAdapter<ItemModel, BaseViewHolder>(R.layout.main_item, datas) {
        override fun convert(holder: BaseViewHolder, item: ItemModel) {
            holder.setText(R.id.tv, item.label)
        }

    }

    data class ItemModel(val label: String, val clazz: Class<out AppCompatActivity>)
}
